package com.bestcem.xm.member.job;

import com.bestcem.xm.componet.xxljob.annotation.XxlRegister;
import com.bestcem.xm.member.service.SendMemberService;
import com.bestcem.xm.member.service.WechatService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MemberJobService {

    private static final Logger logger = LoggerFactory.getLogger(MemberJobService.class);

    /**
     * 推送联系人服务
     */
    @Resource
    private SendMemberService sendMemberService;

    @Resource
    private WechatService wechatService;

    @XxlJob(value = "member-sendMembers-job")
    //@XxlRegister(cron = "0 45 2 * * ?", triggerStatus = 1, jobDesc = "联系人自动打标签定时任务")
    @XxlRegister(cron = "${app.member.job.send-members-cron:0 45 2 * * ?}", triggerStatus = 1, jobDesc = "联系人自动打标签定时任务")
    public void labelJob() {
        logger.info("[MEMBER] 联系人打标签开始");
        sendMemberService.publishMemberSlices();
        logger.info("[MEMBER] 联系人打标签结束");
    }

    @XxlJob(value = "member-wechatInfoSync-job")
    //@XxlRegister(cron = "0 0 1 * * ?", triggerStatus = 1, jobDesc = "同步联系人微信信息定时任务")
    @XxlRegister(cron = "${app.member.job.wechat-info-sync-cron:0 0 1 * * ?}", triggerStatus = 0, jobDesc = "同步联系人微信信息定时任务")
    public void syncMemberFromWxJob() {
        logger.info("[MEMBER] 联系人同步微信信息开始");
        wechatService.publishSyncMemberSlices();
        logger.info("[MEMBER] 联系人同步微信信息结束");
    }

}
